package com.itheima.health.task;

import com.itheima.health.constant.RedisConstant;
import com.itheima.health.util.QiniuUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


import java.util.Set;

@Component
@Slf4j
public class SemealTask {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private QiniuUtils qiniuUtils;

    @Scheduled(cron = "0 0 8 * * ?")
    public void clearImg(){
        log.info("清理垃圾图片开始-------");
        //将redis中的图片 按照键 存入set集合中
        Set<String> set = redisTemplate.opsForSet().members(RedisConstant.SETMEAL_PIC_RESOURCES);
        //循环set集合
        for (String s : set) {
            //删除七云牛中的垃圾图片
            qiniuUtils.deleteFileFromQiniu(RedisConstant.SETMEAL_PIC_RESOURCES);
            //删除redis中的垃圾图片
            redisTemplate.opsForSet().remove(RedisConstant.SETMEAL_PIC_RESOURCES,s);
        }
        log.info("清理垃圾图片结束-------");
    }
//          0 */5 * * * ? 每五分钟执行一次
    @Scheduled(cron = "0 */5 * * * ?")
    public void clearSend(){
        redisTemplate.opsForValue().increment(RedisConstant.MOBILE_SIGNIN);
    }
}
